package bpm.dao.impl.approval;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import bpm.dao.approval.ApprovalDao;
import bpm.domain.approval.ApprovalStatView;
import bpm.domain.approval.ApprovalView;

@Repository("approvalDao")
public class ApprovalImpl implements ApprovalDao {
	@javax.annotation.Resource
	private JdbcTemplate jdbcTemplate;
	
	@SuppressWarnings("unchecked")
	public List<ApprovalView> findList(String sql, Object... objs) {
		return this.jdbcTemplate.query(sql, objs, new RowMapper(){
			public Object mapRow(ResultSet rs, int arg1) throws SQLException {
				ApprovalView view = new ApprovalView();
				view.setId(rs.getString("DOCID"));
				view.setBgtType(rs.getString("BGT_TYPE"));
				view.setTitle(rs.getString("TITLE"));
				view.setDocumentCategory(rs.getInt("CATEGORYID"));
				view.setDocumentCategoryName(rs.getString("CATEGORYNAME"));
				view.setBgtCode(rs.getString("BGT_CODE"));
				view.setPriorityId(rs.getString("PRIORITYID"));
				view.setPriorityName(rs.getString("PRORITYNAME"));
				view.setDrafter(rs.getString("DRAFTER_ID"));
				view.setDraftDeptId(rs.getString("DRAFTER_DEPTID"));
				view.setDrafterName(rs.getString("DRAFTER_NAME"));
				view.setDraftTime(rs.getTimestamp("DRAFT_TIME"));
				return view;
			}});
	}

	@SuppressWarnings("unchecked")
	public List<ApprovalStatView> stat(String sql,RowMapper rowMapper,Object... objs) {
		return this.jdbcTemplate.query(sql, objs, rowMapper);
	}

	public int count(String sql, Object... objs) {
		return this.jdbcTemplate.queryForInt(sql, objs);
	}

}
